<?php
namespace Module\Manage;

use Sfsn\Core\Controller\Controller;
use Sfsn\Core\Util\Lang;
use Sfsn\Lib\DzCrypt;
use Sfsn\Core\Config;
use Model\Member;
use Sfsn\Core\Http\Cookie;
/**
 * 全局初始化
 * @author shooke
 *
 */
class Init extends Controller
{
    public $_G = [];
    public function __construct()
    {
        $this->initLang();
        $this->auth();
    }
    /**
     * 初始化语言包
     */
    public function initLang(){
        $config = [
        'LANG_PACK_FILE' => 'Lang',
        'LANG_PACK_PATH' => './Lang/',
        'LANG_PACK_SUFFIX' => '.php'
        ];
        Lang::init($config);        
    }
    public function auth()
    {
        $cookie = Cookie::get('auth');
        $key = Config::get('AUTH_KEY');
        $member = DzCrypt::decrypt($cookie,$key);
        if($member){
            $where = [
                'username'=>$member['username'],
                'password'=>$member['password']
            ];
            $have = Member::where($where)->fetch();   
            $this->_G['member'] = $member;
            $this->_G['uid'] = $member['uid'];
            $this->_G['username'] = $member['username'];
            $this->assign('_G',$this->_G);      
        }
        if(!$member || !$have){
            $this->redirect('Login/index');
        }
    }
}

?>